package com.wen.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wen.common.dto.UserAddressDTO;
import com.wen.common.pojo.system.User;
import com.wen.common.pojo.system.UserRole;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {


    @Select("select COUNT(id) count , address from cms_user GROUP BY address")
    List<UserAddressDTO> countByAddress();

    // @Param("name") mapper文件中的参数名和形参名不一样的话可用注解指定
    List<User> getUserLike(@Param("abc_name")String name, String address);

    /**
     * id 批量删除
     * @param idList
     * @return
     */
    int deleteBatchByIds(Collection<? extends Serializable> idList);

    @Select("select * from  cms_user where user_name =#{name } and password=#{password} limit 1")
    User login(@Param("name") String name, String password);
    @Select("select * from  cms_user where user_name =#{name } limit 1")
    User findUserByName(String name);
    //----------------以下相当于中间表(用户角色表)里面的
    // -- 根据用户id 查用户角色id  (用户角色表)  一个用户可能有多个角色
    //select * from user_role where user_id = 1
    @Select("select * from cms_user_role where user_id = #{userId}")
    List<UserRole> getUserRoleByUserId(Long userId);

    @Delete("delete from cms_user_role where user_id = #{userId}")
    void deleteUserRoleByUserId(Long userId);

    @Delete("delete from cms_user_role where role_id = #{roleId}")
    void deleteUserRoleByRoleId(Long roleId);

    @Insert("insert into cms_user_role(user_id, role_id) values(#{userId}, #{roleId})")
    void insertUserRole(Long userId, Long roleId);

    @Insert("insert into cms_user values(100,#{username}, #{password},null,null,null,null,null,null,null,null,null,null,null)")
    void insertUserTest(User user);


}
